//
//  MYGAcademicCollectCell.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/6/4.
//

import UIKit
import QMUIKit

class MYGAcademicCollectCell: UITableViewCell {
    
    var clickCollectBlock:((_ id:Int)->Void)?
    private var meeting_id:Int = 0
    
    func bindData(_ model:MYGCollectSpeechModel){
        meeting_id = model.id
        
        var names:[String] = []
        names.append("\(model.speechCn)")
        names.append("\(model.speechEn)")
        model.expert.forEach{ obj in
            names.append("\(obj.expertCn)(\(obj.hospital)/\(obj.expertEn)")
        }
        names.append("\(model.room.sessionCn)-\(model.room.sessionDate)-\(model.room.roomCn)")
        
        let name = names.joined(separator: ",")
        contentlabel.text = name.replacingOccurrences(of: ",", with: "\n")
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .white
        contentView.backgroundColor = .white
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configUI(){
        contentView.addSubviews([contentlabel,collectButton,line])
        contentlabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(25)
            make.top.equalTo(10.5)
        }
        
        line.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(25)
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
        collectButton.snp.makeConstraints { make in
            make.left.equalTo(contentlabel)
            make.height.equalTo(15)
            make.bottom.equalToSuperview().inset(15)
        }
    }
    
    private lazy var contentlabel:UILabel = {
        let label = UILabel()
        label.textColor = .rgba(51, 51, 51, 1)
        label.font = .regular(12)
        label.numberOfLines = 0
        return label
    }()
    
    private lazy var collectButton:QMUIButton = {
        let btn = QMUIButton()
//        btn.setImage(UIImage(named: "meet_collection"), for: .normal)
        btn.setImage(UIImage(named: "meet_collection_sel"), for: .normal)
        btn.setTitle("取消收藏", for: .normal)
        btn.imagePosition = .left
        btn.spacingBetweenImageAndTitle = 5
        btn.titleLabel?.font = .regular(11)
        btn.setTitleColor(.rgba(170, 170, 170, 1), for: .normal)
        btn.addTarget(self, action: #selector(clickColloctButton), for: .touchUpInside)

        return btn
    }()
 
    private lazy var line:UIView = {
        let line = UIView()
        line.backgroundColor = .rgba(238, 238, 238, 1)
        return line
    }()
    
    @objc func clickColloctButton(){
        clickCollectBlock?(meeting_id)
    }
}
